// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
//声明请求对象
const LedgerRequest = {
    // Sub请求的基本url
    BASE_URL : confing.DV_URL + "/machinery",
    //请求Api
    /**
     * 根据ID删除用户
     * @param {*} machineryId
     * @param {*} callback 
     */
    delete(machineryId,callback){
        request.delete(this.BASE_URL + "/deleteById?machineryId=" + machineryId ,callback);
    },
    /**
     * 根据ID编辑用户信息
     * @param {} machinery
     * @param {*} callback  
     */
    edit(machinery,callback){    
        if(machinery != undefined && machinery.machineryId != undefined){
            request.put(this.BASE_URL + "/update",machinery,callback);
        }
    },
     /**
     * 根据id加载用户信息
     * @param {*} machineryId 用户编号
     * @param {*} callback 回调函数
     */
     get(machineryId,callback){
        if(machineryId){
            // 准备url
            let url = this.BASE_URL + "/get?machineryId=" + machineryId;
            request.get(url,callback);
        }
        // 如果没有machineryId，不做任何处理
    },
    /**
     * 保存用户
     * @param {*} machinery 用户对象
     * @param {*} callback  回调函数
     */
    save(machinery,callback){
        let url = this.BASE_URL + "/save";
        request.post(url,machinery,callback);
    },
    list(page = 1,limit = 10,machinery,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(machinery){
            if(machinery.machineryCode){
                url += "&machineryCode=" + machinery.machineryCode;
            }
            if(machinery.machineryName){
                url += "&machineryName=" + machinery.machineryName;
            }
           
        }
        // 发送请求
        request.get(url,callbcak);
    }
}
export default LedgerRequest;